﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace wForm
{
    public partial class frmKategori : Form
    {
        public frmKategori()
        {
            InitializeComponent();
            this.Load += new EventHandler(Form1_Load);

        }
        DataClasses1DataContext db = new DataClasses1DataContext();

        void Form1_Load(object sender, EventArgs e)
        {

            treeList1.DataSource = db.Kategoris; 
        }

        private void buttonEdit1_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
           object o  =treeList1.FocusedNode.GetValue("Id");
           if (o != null)
           {
               int? ustId = (int?)o;

               Kategori yeni = new Kategori();

               yeni.Ad = buttonEdit1.Text;
               yeni.UstKategoriId = ustId;

               db.Kategoris.InsertOnSubmit(yeni);
               db.SubmitChanges(); 
               treeList1.DataSource = db.Kategoris.ToList();
               treeList1.RefreshDataSource();
               treeList1.Refresh();

               buttonEdit1.Text = string.Empty;
               
           }
           else MessageBox.Show("Üst Kategori Seç");
        }

        private void treeList1_SelectionChanged(object sender, EventArgs e)
        {

        }
    }
}
